package com.shanwen.select.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @author 刘栋
 * @ClassName: Menu
 * @Description: TODO 菜单
 * @date 2019年3月7日 上午11:17:10
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
public class Menu implements Comparable<Menu> {
    /**
     * 串行版本ID
     */
    private static final long serialVersionUID = 8430092145864769458L;

    /**
     * 菜单id
     */

    private Integer id;

    /**
     * 菜单名称
     */
    private String menuName;

    /**
     * 菜单地址
     */
    private String url;

    /**
     * 状态
     */
    private Integer status;

    /**
     * 父级id
     */
    private Integer parent;

    /**
     * 权限关键词
     */
    private String authorityKey;
    /**
     * 菜单排序，按照数字大小排列
     */
    private Integer menuSort;
    /**
     * 该节点下的子节点compareTo
     */
    @TableField(exist = false)
    private List<Menu> children = new ArrayList<Menu>();
    // 是否显示
    private Integer isShow;
    // 图标显示
    private String icon;

    // 当前角色是否包含该菜单的权限
    @TableField(exist = false)
    private Integer isHave;


    // 重写排序方法compareTo
    @Override
    public int compareTo(Menu o) {
        int i = 0;
        try {
            i = this.getMenuSort() - o.getMenuSort();

        } catch (Exception e) {
            System.out.println("this is id=" + this.getId() + "  this is o=" + o.getId());
        }
        return i;
    }

    public List<Menu> getChildren() {
        return children;
    }

    public void setChildren(List<Menu> children) {
        if (children != null && children.size() > 0) {
            Collections.sort(children);
        }

        this.children = children;
    }


    public Menu() {

    }
}
